﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastData
{
    public static class DesignHelper
    {
        static readonly object lock_obj = new object();
        public static bool IsDesignMode
        {
            get
            {
                bool returnFlag = false;
                if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
                {
                    returnFlag = true;
                }
                else if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
                {
                    returnFlag = true;
                }
                return returnFlag;
            }
        }

        public static void Log(string content)
        {
            lock (lock_obj)
            {
                DateTime dateTime = File.GetLastWriteTime("D:\\DesignerLog.txt");
                TimeSpan timeSpan = DateTime.Now - dateTime;
                if (timeSpan > new TimeSpan(5, 0, 0, 0))
                {
                    File.Delete("D:\\DesignerLog.txt");
                }
                File.AppendAllLines("D:\\DesignerLog.txt", new string[] { $"[{DateTime.Now.ToString()}]\t{content}" }, Encoding.Default);
            }
        }
    }
}

